/*
 Copyright (C) 2008 PAUCARD Charlie

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef _WIIMOTE_H
#define	_WIIMOTE_H

#define M_DEFAULT_TIMEOUT 5

//All the defines that tell the user what key is pressed, and what happened
#define WM_DISCONNECTED 2.0 //The wiimote disconnected
#define WM_UNKNOWN -1.0
#define WM_EVENT 1.0 //An event occured
    #define WM_BUTTON_A 1.0
    #define WM_BUTTON_B 2.0
    #define WM_BUTTON_UP 3.0
    #define WM_BUTTON_DOWN 4.0
    #define WM_BUTTON_LEFT 5.0 
    #define WM_BUTTON_RIGHT 6.0
    #define WM_BUTTON_MINUS 7.0
    #define WM_BUTTON_PLUS 8.0
    #define WM_BUTTON_ONE 10.0
    #define WM_BUTTON_TWO 11.0
    #define WM_BUTTON_HOME 12.0
    #define WM_EVENT_OTHER -1.0
#define WM_ACC 13.0
    #define WM_ACC_DISABLED -1.0
#define WM_IR 14.0
    #define WM_IR_DISABLED -1.0
    #define WM_IR_NO_SOURCE -2.0

#include <wiiuse.h>
#include <vector>
#include <string>
#include <iostream>

class WM
{
public:
    WM(bool actAcc, bool actIR, int nbWiiMotes=1); //Default constructor
    
    ~WM(); //Destructor
    
    bool eventHappened(void); //If an event happened
        std::vector<double> getEvent(int wiimoteNb); //When an event happens, we get the event (only butons, no IR/Acc
        std::vector<double> getAccData(int wiimoteNb); //Acc Data
        std::vector<double> getIRData(int wiimoteNb); //IR Data
        
    //Setters
    void setAcc(bool choice); //Used to activate accelerometer, on all wiimotes
    void setAcc(bool choice, int wiimoteNb); //Used to activate accelerometer
    void setIR(bool choice); //Used to activate IR, on all wiimotes
    void setIR(bool choice, int wiimoteNb); //Used to activate IR
    void setRumble(bool choice); //Activate / Deactivate the rumble
    void setRumble(int wiimoteNb, bool choice); //Toogle (ON/OFF) the ruble of the wiimote
    void setLED(int wiimoteNb, int led); //Set the LED of a Wiimote
    //Getter
    bool getIR(int wiimoteNb); //Check if using IR
    bool getAcc(int wiimoteNb); //Check if using Acc
    int getBattery(int wiimoteNb); //Get battery remaining
    
    
private:
    wiimote** m_wiimotes; //The actual wiimote array
    int M_NB_WIIMOTES;
    
    std::vector<double> handleEvent(int wiimoteNb); //handle a given event
};

#endif	/* _WIIMOTE_H */

